﻿//********************************************************************************//
//创建日期：<创建日期，2016-02-26>
//创建作者：<郭登杰，guodengjie@shanghai3h.com>
//功能说明：涉水对象分类
//********************************************************************************//
using System;
using System.Web.UI;
using Entity;
using BLL;
using System.Data;
using Web.Class;

namespace Web.Pages.YongShui.JiChuXX
{
    public partial class SheShuiDXFL : BasePage
    {
        #region 属性

        /// <summary>
        ///当前操作项ID
        /// </summary>
        private int SheShuiDXID
        {
            get
            {
                return Convert.ToInt32(ViewState["_SheShuiDXID"]);
            }
            set
            {
                ViewState["_SheShuiDXID"] = value;
            }
        }

        /// <summary>
        /// 保存结果集
        /// </summary>
        private DataTable dtSource
        {
            get
            {
                return ViewState["dtSource"] as DataTable;
            }
            set
            {
                ViewState["dtSource"] = value;
            }
        }

        #endregion

        #region 变量

        /// <summary>
        /// 涉水对象 对象
        /// </summary>
        YS_JX_SHESHUIDX _YS_JX_SHESHUIDX = new YS_JX_SHESHUIDX();

        /// <summary>
        /// 泪水对象BLL
        /// </summary>
        YS_JX_SHESHUIDXBLL _YS_JX_SHESHUIDXBLL = new YS_JX_SHESHUIDXBLL();

        /// <summary>
        /// 操作日志BLL
        /// </summary>
        SYS_LOGBLL _SYS_LOGBLL = new SYS_LOGBLL();

        #endregion

        #region 事件

        /// <summary>
        ///页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次页面加载
            if (!IsPostBack)
            { 
                InitData();                
            }
            LoadData();
        }

        /// <summary>
        /// 重写Render方法绑定空表头
        /// </summary>
        protected override void Render(HtmlTextWriter sender)
        {
            //绑定空表头
            base.Render(sender);
        }

        /// <summary>
        /// 响应前台回调
        /// </summary>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            CallbackResult cr = new CallbackResult(e.Parameter);
            int id = Convert.ToInt32(this.hdCollection.Get("ID"));
            if (e.Parameter == "info")
            {
                this._YS_JX_SHESHUIDX = this._YS_JX_SHESHUIDXBLL.SelectYS_JX_SHESHUIDX(id);
                cr.IsSuccess = true;
                cr.IsAlertMsg = false;
                cr.AddValue(this._YS_JX_SHESHUIDX.S_DAIMA, this._YS_JX_SHESHUIDX.S_NAME);
                e.Result = cr.ToString();
                return;
            }
            else if (e.Parameter == "del")
            {
                //执行逻辑删除
                this._YS_JX_SHESHUIDX = this._YS_JX_SHESHUIDXBLL.SelectYS_JX_SHESHUIDX(id);
                _YS_JX_SHESHUIDX.S_CAOZUOR = LoginInfo.CurrentUser.Account;
                _YS_JX_SHESHUIDX.D_CAOZUOSJ = BusinessTool.GetDataBaseDateTime();
                _YS_JX_SHESHUIDX.I_JLZT = -1;
                _SYS_LOGBLL.Log<YS_JX_SHESHUIDX>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "涉水对象分类", OperateState.Delete, _YS_JX_SHESHUIDX, null);
                if (_YS_JX_SHESHUIDXBLL.InsertOrUpdate(_YS_JX_SHESHUIDX, null))
                {
                   
                    cr.IsSuccess = true;
                    cr.IsAlertMsg = true;
                    cr.Msg = "操作成功！";
                    e.Result = cr.ToString();
                    return;
                }
            }
            else if (e.Parameter == "save")
            {
                OperateState operateState;
                //添加
                if (id == -1)
                {
                    _YS_JX_SHESHUIDX.ID = 0;
                    _YS_JX_SHESHUIDX.I_JLZT = 0;
                    operateState = OperateState.Add;
                }
                //修改
                else
                {
                    //修改操作
                    _YS_JX_SHESHUIDX = _YS_JX_SHESHUIDXBLL.SelectYS_JX_SHESHUIDX(id);
                    operateState = OperateState.Modify;
                }
                //判断编号是否存在
                if (_YS_JX_SHESHUIDXBLL.SelectYS_JX_SHESHUIDXesDynamic(string.Format("I_JLZT=0 and S_DAIMA='{0}' and ID<>'{1}'", this.txtNo.Text, this._YS_JX_SHESHUIDX.ID), null).Rows.Count > 0)
                {
                    cr.IsSuccess = false;
                    cr.IsAlertMsg = true;
                    cr.Msg = "您所输入涉水对象分类代码系统中已经存在使用,请修改。";
                    e.Result = cr.ToString();
                    return;
                }
                _YS_JX_SHESHUIDX.S_DAIMA = this.txtNo.Text;
                _YS_JX_SHESHUIDX.S_NAME = this.txtName.Text;
                this._YS_JX_SHESHUIDX.S_CAOZUOR = LoginInfo.CurrentUser.Account;
                this._YS_JX_SHESHUIDX.D_CAOZUOSJ = BusinessTool.GetDataBaseDateTime();
                _SYS_LOGBLL.Log<YS_JX_SHESHUIDX>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "涉水对象分类", operateState, _YS_JX_SHESHUIDX, null);
                if (_YS_JX_SHESHUIDXBLL.InsertOrUpdate(_YS_JX_SHESHUIDX))
                {
                    
                    cr.IsSuccess = true;
                    cr.IsAlertMsg = true;
                    cr.Msg = "保存成功！";
                    cr.SpecialIndetity=_YS_JX_SHESHUIDX.ID.ToString();
                    e.Result = cr.ToString();
                    return;
                }
            }
        }

        #endregion

        #region 方法

        /// <summary>
        /// 初始化数据
        /// </summary>
        private void InitData()
        {
            
        }

        /// <summary>
        /// 数据加载
        /// </summary>
        private void LoadData()
        {
            gvSheShuiDXFL.DataSource = _YS_JX_SHESHUIDXBLL.SelectYS_JX_SHESHUIDXesAll();
            gvSheShuiDXFL.DataBind();
        }

        #endregion
    }
}